<template>
	<view>
		<nav-bar title="订单详情"></nav-bar>
		<scroll-view scroll-y :style="{ height: '90vh' }">
			<view class="address-box" v-if="orderType !== 3">
				<view class="person-box">
					<view class="user-name">{{ chooseAddress.userName }}</view>
					<view class="phone">{{ chooseAddress.phoneNumber }}</view>
				</view>
				<view class="address">{{ chooseAddress.address }}</view>
			</view>
			<view class="goods-list">
				<view class="goods-item" v-for="(item, index) in goodsList" :key="index">
					<view class="left-img">
						<image class="goods-img" :src="baseUrl+item.goodImg" mode="aspectFill" />
					</view>
					<view class="goods-content">
						<view class="goods-name">{{ item.goodName }}</view>
						<view class="num-box">
							<view class="size-box">X{{ item.goodCount }}</view>
							<view class="price"><text class="icon">￥</text>{{ item.goodPrice }}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="send-type">
				<view class="send-item" v-if="orderType !== 3">
					<view class="item-label">配送方式</view>
					<view class="item-value">
						<view class="common">
							<text class="word">{{ item.deliveryType == 1? '普通配送' : '加急配送' }}</text>
						</view>
					</view>
				</view>
				<view class="desc-text">
					{{ remark }}
				</view>
				<view class="send-item" v-if="orderType !== 3">
					<view class="item-label">配送费</view>
					<view class="item-value">
						<text class="num">￥</text><text class="money">{{ deliveryCost }}</text>
					</view>
				</view>
				<view class="send-item">
					<view class="item-label">订单总价</view>
					<view class="item-value">
						<text class="num">￥</text><text class="money">{{ allAccount }}</text>
					</view>
				</view>
				<view class="send-item">
					<view class="item-label">下单时间</view>
					<view class="item-value">
						<view class="pay">{{createTime}}</view>
					</view>
				</view>
				<view class="send-item">
					<view class="item-label">订单编号</view>
					<view class="item-value">{{ orderNo }}</view>
				</view>
				<view class="send-item delivery" v-if="orderType !== 3">
					<view class="item-label">送达图片</view>
					<view class="item-img" v-if="receiveImgUrl">
						<image style="width: 200rpx;margin-top: 20rpx; margin-right: 10rpx;"
							v-for="item,index in receiveImgUrl" :key="index" :src="baseUrl+item" mode="widthFix">
						</image>
					</view>
					<view v-else class="item-value">暂无</view>
				</view>
				<view class="send-item delivery" v-if="orderType !== 3">
					<view class="item-label">送达说明</view>
					<view v-if="receiveRemark" style="margin-top: 20rpx;" class="item-value">{{ receiveRemark }}</view>
					<view v-else class="item-value">暂无</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		baseUrl,
		baseImgUrl,
		baseIconUrl
	} from '@/config'
	export default {
		name: 'OrderDetail',
		data() {
			return {
				baseUrl,
				id: '',
				orderNo: '',
				createTime: '',
				deliveryCost: '',
				baseImgUrl,
				baseIconUrl,
				scrollHeight: '',
				allAccount: '',
				remark: '',
				chooseAddress: {},
				goodsList: [],
				curIndex: 0,
				sendType: ['普通配送', '加急配送'],
				receiveRemark: '',
				receiveImgUrl: [],
				orderType: 2,
			}
		},
		onLoad(options) {
			console.log(options);
			this.id = options.id
			this.scrollHeight = this.$store.getters.heightData.noTabMainHeigh + 'px'
			this.getGoodsList()
		},
		methods: {
			async getGoodsList() {
				const res = await this.$GET(`/fx/order/${this.id}`)
				console.log(res)
				this.orderType = res.data.orderType
				if (res.code == 200) {
					this.goodsList = res.data.fxOrderItemList
					this.chooseAddress = {
						userName: res.data.receiveName,
						phoneNumber: res.data.receivePhonenum,
						address: res.data.receiveAddress
					}
					this.remark = res.data.remark
					this.orderNo = res.data.id
					this.createTime = res.data.createTime
					this.allAccount = res.data.payMoney
					this.deliveryCost = res.data.deliveryCost
					this.receiveRemark = res.data.receiveRemark
					this.receiveImgUrl = res.data.receiveImgUrl.split(',')
				}
				// this.goodsList = [{
				// 		name: '左钢铰链304不锈钢合叶弹簧阻尼缓冲五金配件 折叠橱柜...',
				// 		price: '3.5',
				// 		size: '1寸（201不锈钢）',
				// 		number: 1,
				// 		img: `${this.baseImgUrl}images_order.png`
				// 	},
				// 	{
				// 		name: '左钢铰链304不锈钢合叶弹簧阻尼缓冲五金配件 折叠橱柜...',
				// 		price: '3.5',
				// 		size: '1寸（201不锈钢）',
				// 		number: 1,
				// 		img: `${this.baseImgUrl}images_order.png`
				// 	},
				// 	{
				// 		name: '左钢铰链304不锈钢合叶弹簧阻尼缓冲五金配件 折叠橱柜...',
				// 		price: '3.5',
				// 		size: '1寸（201不锈钢）',
				// 		number: 1,
				// 		img: `${this.baseImgUrl}images_order.png`
				// 	},
				// 	{
				// 		name: '左钢铰链304不锈钢合叶弹簧阻尼缓冲五金配件 折叠橱柜...',
				// 		price: '3.5',
				// 		size: '1寸（201不锈钢）',
				// 		number: 1,
				// 		img: `${this.baseImgUrl}images_order.png`
				// 	}
				// ]
			},
			clickAddressManage() {
				uni.navigateTo({
					url: `/subPages/store/myAddress`
				})
			},
			clickGoodsItem(item) {
				uni.navigateTo({
					url: `/subPages/store/goodsDetail`
				})
			},
			//配送点击事件
			sendClick(val, index) {
				this.curIndex = index
			}
		}
	}
</script>
<style lang="scss" scoped>
	.address-box {
		margin: 20rpx 28rpx;
		padding: 20rpx 24rpx;
		border-radius: 12rpx;
		background-color: #FFF;

		.person-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 8rpx;
			font-size: 28rpx;

			.phone {
				flex: 1;
				margin: 0 20rpx;
			}
		}

		.address {
			font-size: 24rpx;
			line-height: 44rpx;
			color: #808080;
		}
	}

	.goods-list {
		margin: 20rpx 28rpx;

		.goods-item {
			display: flex;
			margin-bottom: 20rpx;
			padding: 20rpx 24rpx;
			border-radius: 12rpx;
			background-color: #FFF;

			.left-img {
				width: 140rpx;
				height: 140rpx;
				margin-right: 14rpx;
				border-radius: 8rpx;
				overflow: hidden;
				background-color: #cfd2ca;

				.goods-img {
					width: 100%;
					height: 100%;
				}
			}

			.goods-content {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.goods-name {
					font-size: 28rpx;
				}

				.num-box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 8rpx;
					font-size: 24rpx;

					.size-box {
						color: #808080;
					}

					.price {
						font-size: 26rpx;
						color: #EB2727;

						.icon {
							font-size: 20rpx;
						}
					}
				}
			}
		}
	}

	.send-type {
		margin: 20rpx 28rpx;
		padding: 20rpx 24rpx;
		border-radius: 12rpx;
		background-color: #FFF;

		.send-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;

			.item-value {
				display: flex;
				align-items: center;

				.num,
				.money {
					display: block;
					font-size: 28rpx;
					color: #0b3f35;
				}

				.common {
					display: flex;
					align-items: center;
					margin-left: 80rpx;
				}

				.word {
					margin-left: 16rpx;
				}
			}

			.value-btn {
				width: 40rpx;
				height: 40rpx;
			}

			.btn-img {
				width: 100%;
				height: 100%;
			}

			.pay {
				margin-left: 10rpx;
			}
		}

		.delivery {
			display: block;
		}
	}

	.desc-text {
		padding: 30rpx;
		border-radius: 8rpx;
		background: #F2F2F2;
		max-height: 6em;
		/* 限制最大高度为三行文本 */
		line-height: 2em;
		/* 每行文本的高度 */
	}
</style>